/* 
Code creates average trajectories observed in the observational data 
(i.e. proportion of girls in school and married at different ages) and standard errors therein
*/

* load cleaned data	
*-------------------------------------------------------------------------------
use "$data/created_data/Observed Trajectories (5-year FU) -- cleaned", clear

* merge in parental perceptions at EL and generate heterogeneity splits
*-------------------------------------------------------------------------------
merge 1:1 girl_id using "$data/initial_data/Parental Perceptions of Daughters (EL)", 
drop _merge

* define the indicators we will use for breaking gender norms and being hardworking
*-------------------------------------------------------------------------------
* parents are worried about breaking gender norms
gen parents_worried=(m403_new4>1 | m403_new5<5 | m403_new6<3) if mi(m403_new6,m403_new5,m403_new4)==0

* girl is hard working
gen hard_working=(m403_r>3) if m403_r<.
tab hard_working

* cross tab the two indicators -- we will use this to construct the aggregate implied trajectories (see "programs" file)
tab hard_working parents_worried

* reshape observational trajectory data
*-------------------------------------
reshape long inschool married dropout, i(girl_id) j(age)	

* create average trajectories and standard errors
*-------------------------------------------------------------------------------
preserve

collapse (mean) inschool married  (count) n_inschool=inschool n_married=married n_dropout=dropout, by(age)

rename  inschool inschool_obs
rename married married_obs 

gen married_obs_se=(married*(1-married)/n_married)^0.5
gen inschool_obs_se=(inschool*(1-inschool)/n_inschool)^0.5

keep if age>12 & age<23 
drop n*
save "$data/created_data/obs_traj", replace
restore


* by hard working
*-------------------------------------------------------------------------------
preserve
drop if hard_working==.
collapse (mean) inschool married  (count) n_inschool=inschool n_married=married n_dropout=dropout, by(age hard_working)

rename  inschool inschool_obs
rename married married_obs 

gen married_obs_se=(married*(1-married)/n_married)^0.5
gen inschool_obs_se=(inschool*(1-inschool)/n_inschool)^0.5

keep if age>12 & age<23 
drop n*
rename hard_working likeschool
save "$data/created_data/obs_traj_hard_working", replace
restore


* by parents worried
*-------------------------------------------------------------------------------
preserve
drop if parents_worried==.
collapse (mean) inschool married  (count) n_inschool=inschool n_married=married n_dropout=dropout, by(age parents_worried)

rename  inschool inschool_obs
rename married married_obs 

gen married_obs_se=(married*(1-married)/n_married)^0.5
gen inschool_obs_se=(inschool*(1-inschool)/n_inschool)^0.5

keep if age>12 & age<23 
drop n*
gen goodgirl=1-parents_worried
save "$data/created_data/obs_traj_parents_worried", replace
restore
